<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <script type="text/javascript" src="static/js/jquery.min.js"></script>
    <script type="text/javascript"
            src="static/js/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet"
          href="static/js/bootstrap/css/bootstrap.min.css" />
    <link rel="stylesheet"
          href="static/js/bootstrap/css/bootstrap-treeview.min.css"
          th:href="@{static/js/bootstrap/css/bootstrap-treeview.min.css}"
    >
    <script src="static/js/bootstrap/js/bootstrap-treeview.min.js"></script>
    <link rel="stylesheet"
          href="static/js/bootstrap/css/bootstrap.addtabs.css">
    <script src="static/js/bootstrap/js/bootstrap.addtabs.min.js"></script>
    <link rel="stylesheet" href="static//js/bootstrap/css/bootstrap-table.min.css">
    <script src="static/js/bootstrap/js/bootstrap-table.min.js"></script>
    <script src="static/js/bootstrap/js/bootstrap-table-zh-CN.min.js"></script>
    <script src="static/js/bootstrap/js/bootbox.js"></script>
    <link rel="stylesheet"
          href="static/js/bootstrap/css/bootstrap-datetimepicker.min.css" />
    <script type="text/javascript"
            src="static/js/bootstrap/js/bootstrap-datetimepicker.min.js"></script>
    <script type="text/javascript"
            src="static/js/bootstrap/js/bootstrap-datetimepicker.zh-CN.js"></script>
    <script src="static/js/bootstrap-fileinput/js/fileinput.js"></script>
    <script src="static/js/bootstrap-fileinput/js/locales/zh.js"></script>
    <link rel="stylesheet" href="static/js/bootstrap-fileinput/css/fileinput.css">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.18/dist/js/bootstrap-select.min.js"></script>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.18/dist/css/bootstrap-select.min.css">

</head>
<body onload="showSel()" >
<div id="toolBar">
    <div className="form-group">
        <label htmlFor="orderDesc">项目名称:</label>
        <input type="text" className="form-control" id="productName"/>

        <label htmlFor="orderDesc">状态:</label>
        <select class="selectpicker form-control" data-width="150px" id="queryPriceStatus">
            <option value="-1" >请选择</option>
            <option value="1" >即将开始</option>
            <option value="2" >进行中</option>
            <option value="5" >已结束</option>
        </select>

        <label htmlFor="orderDesc">活动时间:</label>
        <input type="date" className="form-control" id="starDate"/>
        <input type="date" className="form-control" id="endDate"/>

        <button type="button" onClick="search()" className="btn btn-info glyphicon glyphicon-search">搜索</button>
    </div>
</div>


<table id="myTable"></table>
</body>
<script type="text/javascript">

    // /**
    //  * 状态动态下拉
    //  */
    // function showSel(){
    //     $.ajax({
    //         "type" : 'get',
    //         "url": 'getPriceSelectClass',
    //         "dataType" : "json",
    //         "success" : function(data) {
    //             var arr = data;
    //             var opts = "";
    //             for( var i = 0 ; i < arr.length; i++ ){
    //                 var depart = arr[i];
    //                 opts += "<option value='"+depart.statusId+"'>"+depart.statusName+"</option>";
    //             }
    //             // 查询界面
    //             $("#queryPriceStatus").append(opts);
    //             $("#queryPriceStatus").selectpicker("refresh");
    //         }
    //     });
    // }
    /**
     * 条查
     */
    function search(){
        $('#myTable').bootstrapTable('refresh');
    }


    /**
     * 查询列表
     */
    $("#myTable").bootstrapTable({
        url:"/getCommonTable",
        columns:[
            {checkbox:true},//是否展示复选框
            {field:'productId',title:'项目编码',align:'center',width:150},
            {field:'productName',title:'项目名称',align:'center',width:150,formatter:function (value, row){
                return "<a href='javascript:particulars(\""+row.productId+"\")'>"+value+"</a>";
                }},
            {field:'statusName',title:'状态',align:'center',width:150,formatter:function (value,row){
                if(row.queryPriceStatus == 1) {
                    return  "即将开始";
                }
                if (row.queryPriceStatus == 16){
                        if (row.estimatePirceType == 0){
                            return "待报价";
                        }else{
                            return "已报价";
                        }
                    }
                if (row.queryPriceStatus == 2){
                    if (row.estimatePirceType == 0){
                        return "待报价";
                    }else{
                        return "已报价";
                    }
                }
                if(row.queryPriceStatus == 5){
                    return "已结束"
                }
                if (row.queryPriceStatus == 14 && row.picketageStatus == 1 && row.estimatePirceType == 1) {
                    return "已中标";
                } else if( row.queryPriceStatus == 14 && row.picketageStatus == 0 && row.estimatePirceType == 1) { //未中标 但是已报价
                    return "未中标"
                } else if (row.queryPriceStatus == 14 && row.estimatePirceType == 0) {
                    return "未报价"
                }

            }},
            {field:'queryPriceEndDate',title:'报价结束时间',align:'center',width:150},
            {field:'productCount',title:'采购数量',align:'center',width:150},
            {field:'cz',title:'操作',formatter:function(value,row){
                    var str = "";
                   if(row.queryPriceStatus == 2){
                       if(row.estimatePirceType == 0){
                           str+="| <a href='javascript:showMaterials(\""+row.queryPriceId+"\",\""+row.productId+"\")'>我要报价</a> |";
                       }else if(row.estimatePirceType == 1){
                           str+="| <a href='javascript:queryOffer(\""+row.queryPriceId+"\")'>查看报价</a> |";
                           str+="| <a href='javascript:updateOffer(\""+row.queryPriceId+"\")'>更新报价</a> |";
                           str+="| <a href='javascript:giveUpById(\""+row.productId+"\")'>放弃报价</a> |";
                       }else{
                           str+="| <a href='javascript:queryOffer(\""+row.queryPriceId+"\")'>查看报价</a> |";
                           str+="| <a href='javascript:giveUpById(\""+row.productId+"\")'>放弃报价</a> |";
                       }
                    }

                    if(row.queryPriceStatus == 16){
                        if(row.estimatePirceType == 0){
                            str+="| <a href='javascript:showMaterials(\""+row.queryPriceId+"\",\""+row.productId+"\")'>我要报价</a> |";
                        }else if(row.estimatePirceType == 1){
                            str+="| <a href='javascript:queryOffer(\""+row.queryPriceId+"\")'>查看报价</a> |";
                            str+="| <a href='javascript:updateOffer(\""+row.queryPriceId+"\")'>更新报价</a> |";
                            str+="| <a href='javascript:giveUpById(\""+row.productId+"\")'>放弃报价</a> |";
                        }else{
                            str+="| <a href='javascript:queryOffer(\""+row.queryPriceId+"\")'>查看报价</a> |";
                            str+="| <a href='javascript:giveUpById(\""+row.productId+"\")'>放弃报价</a> |";
                        }
                    }
                   if (row.queryPriceStatus == 14 && row.picketageStatus == 1 && row.estimatePirceType == 1) { //已中标
                                str+="| <a href='javascript:queryOffer(\""+row.queryPriceId+"\")'>查看报价</a> |";
                                str+="| <a href='javascript:updateById(\""+row.queryPriceId+"\")'>查看订单</a> |";
                            } else if(row.queryPriceStatus == 14 && row.picketageStatus == 0 && row.estimatePirceType == 1) { //未中标 但是已报价
                                str+="| <a href='javascript:queryOffer(\""+row.queryPriceId+"\")'>查看报价</a> |";
                            } else if (row.queryPriceStatus == 14 && row.estimatePirceType == 0) { //未报价
                                    return "未报价"
                            }

                    return str;
                }}
        ],
        //开启分页以后，默认会传入两个参数,而这两个参数，直接是mysql的分页计算后的数据
        pagination:true,
        pageSize:2,
        pageList:[2,4,6,8,10],
        sidePagination : 'client',//server:服务器端分页{rows:[],total:10}|client：前端分页 [{},{}]
        toolbar:'#toolBar',
        queryParams:function(){
            var productName = $("#productName").val();
            var queryPriceStatus = $("#queryPriceStatus").val();
            var starDate = $("#starDate").val();
            var endDate = $("#endDate").val();
            return {
                'productName':productName,
                'starDate':starDate,
                'endDate':endDate,
                'queryPriceStatus':queryPriceStatus
            };
        },

    })


    /**
     * 放弃报价
     */
    function giveUpById(productId){
        $.ajax({
            url:"giveUpById?productId="+productId,
            success:function(){
                $("#myTable").bootstrapTable("refresh");
            }
        })

    }


    /**
     * 更新报价回显
     */
    function updateOffer(queryPriceId){
        location.href="updateOfferWzy?queryPriceId="+queryPriceId;
    }


    /**
     * 我要报价
     * @param queryPriceId
     */
    function showMaterials(queryPriceId,productId){
        location.href="gotoOffer?showPriceId="+queryPriceId+"&productId="+productId;
    }


    /**
     * 查看报价
     * @param productId
     */
    function queryOffer(queryPriceId){
        location.href="queryOffer?id="+queryPriceId;
    }





    /**
     * 查看项目详细信息
     */
    function particulars(productId){
        location.href="particulars?productId="+productId;
    }

</script>
</html>